package org.opens;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.opens.entity.EduCourse;
import org.opens.service.EduCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {MybatisCommonApplication.class})
public class Java8LocalDateUsage {

    @Autowired
    private EduCourseService eduCourseService;

    @Test
    public void test1() {
        eduCourseService.findById(2).ifPresent(System.out::println);
    }

    @Test
    public void test2() {
        String startDate = "2021-04-11 13:12";
        List<EduCourse> result = eduCourseService.findByScheduledStartDatetime(startDate);
        System.out.println(result);
    }

    @Test
    public void test3() {
        EduCourse course = new EduCourse();
        course.setCourseName("cc222");
        course.setScheduledStartDatetime(LocalDateTime.now());
        course.setScheduledEndDatetime(LocalDateTime.of(LocalDate.parse("2032-01-08"), LocalTime.of(23, 59, 59)));
        eduCourseService.save(course);
    }

}
